//
//  ProductListCell.m
//  TestPrj
//
//  Created by 朱铅峰 on 2020/6/22.
//  Copyright © 2020 Xing. All rights reserved.
//

#import "ProductListCell.h"
#import <Masonry.h>

@interface ProductListCell()

proStrong UIImageView *iconView;
proStrong UILabel *nameLabel;

@end

@implementation ProductListCell

+ (CGFloat)cellHeight {
    
    return 70;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addView];
    }
    return self;
}

- (void)addView {
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.separatorInset = UIEdgeInsetsMake(0, 10, 0, 10);
    
    self.iconView = [[UIImageView alloc] init];
    [Utils resetView:self.iconView bgColor:[UIColor whiteColor] cornerRadius:5 borderWidth:0.5 borderColor:kColorLineColor];
    [self.contentView addSubview:self.iconView];
    
    self.nameLabel = [Utils genLabelWithFrame:CGRectZero textAlign:NSTextAlignmentLeft fontSize:14 textColor:kColorBlack];
    self.nameLabel.numberOfLines = 0;
    [self.contentView addSubview:self.nameLabel];
    
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(50);
        make.left.mas_equalTo(10);
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(10);
    }];
}

- (void)loadData:(MTProduct *)data {
    
    self.iconView.image = [UIImage imageNamed:data.iconName];
    
    self.nameLabel.text = data.title;
}

@end
